#include <BleKeyboard.h>
#include <WiFi.h>

int capacitiveValue = 100;  
int threshold = 20; //识别是否被触摸的阈值



BleKeyboard bleKeyboard("ESP32蓝牙键盘","Espressif",100);//其中“ESP32蓝牙键盘”为键盘名称；"Espressif"为制造商
 
void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  bleKeyboard.begin();
}
 
void loop() {
  if(bleKeyboard.isConnected()) {//判断是否连接，链接了就执行下面的代码
    
   
    //Serial.println("下面填入你的开机密码↓");
    //bleKeyboard.print(capacitiveValue = touchRead(4));//要打印字符串用print
    while (true){

    capacitiveValue = touchRead(4);
    if(capacitiveValue < threshold)
    {
      //bleKeyboard.write(KEY_RETURN);
      //bleKeyboard.print("8888");
      //这种功能键用press，代表一直按着
      bleKeyboard.press(KEY_LEFT_GUI);
      bleKeyboard.press(KEY_TAB);
      delay(100);
      bleKeyboard.releaseAll();//代表抬起所有按键，要不然会显示一直按着上面的按键
    }
    //delay(100);
    //Serial.println("回车键");
    //bleKeyboard.write(KEY_RETURN);//回车键这种用weite，代表单次键入
    delay(5000);
    }

  }
  //Serial.println("Waiting 5 seconds...");
  delay(5000);
}